public abstract class Canvas {

  Action activeAction = null;
  PGraphics pg;
  int h, w;
  color backgroundColor;
  PVector origin;

  public Canvas(PVector origin, int h, int w, color backgroundColor) {
    this.origin = origin;
    this.h = h;
    this.w = w;
    this.pg = createGraphics(w, h);
    this.backgroundColor = backgroundColor;
  }

  public abstract void draw();

  public void mouseMove(float parentX, float parentY) {
    if (isInside(parentX, parentY)) {
      if (activeAction!=null) {
        activeAction.mouseMove(parentX - origin.x, parentY - origin.y);
      }
    }
  }    

  public void mouseDrag(float parentX, float parentY) {
    if (isInside(parentX, parentY)) {
      if (activeAction!=null) {
        activeAction.mouseDrag(parentX - origin.x, parentY - origin.y);
      }
    }
  }

  public void mouseClick(float parentX, float parentY) {
    if (isInside(parentX, parentY)) {
      if (activeAction!=null) {
        activeAction.mouseClick(parentX - origin.x, parentY - origin.y);
      }
    }
  }

  public void mousePress(float parentX, float parentY) {
    if (isInside(parentX, parentY)) {
      if (activeAction!=null) {
        activeAction.mousePress(parentX - origin.x, parentY - origin.y);
      }
    }
  }

  private boolean isInside(float parentX, float parentY) {
    return (parentX < origin.x + w && parentX > origin.x && parentY < origin.y + h && parentY > origin.y);
  }

  public void setActiveAction(Action a) {
    activeAction = a;
  }
  
  public PGraphics getPGraphics(){
    return pg;
  }
}

